<% @i = 0%>
<%= javascript_include_tag 'ufo' %>
<script type="text/javascript">
  (function($){
    $(function(){
      $("button#add_to_cart_button").click(function(){
        var button = this;
        $(button).attr("disabled", "disabled");
        $.get('<%= url_for(:controller => "cart", :action => "add", :id => @artwork.id) %>', null,
        function(data){
          $("#cart_total_items").html(data);
          $(button).text("Added to cart");
          setTimeout(function(){
            $(button).attr("disabled", "").text("Add to Cart");
          }, 3000)
        });
      });
    });
  })(jQuery);
</script>
<div id="product_main">
	<h1 class="large_title"><%= @artwork.name %></h1>
	<p class="sub_h2">by <%= link_to @artwork.artist.name, @artwork.artist %> from the <%= link_to @artwork.artist.region.name, @artwork.artist.region %> region</p>
	<div class="col2">
		<div class="left">
			<% if @artwork.medias.size > 0 %>
			<div class="flicker">
				<% @pictures = Picture.find_all_by_artwork_id(@artwork.id)%>
				<% @images = Array.new(@pictures.length) %>
				<% j = 0%>
				<% for @media in @pictures%>
					<% @images[j] = '/picture/file/' + @media.file_relative_path(subdir="medium") %>
					<% j = j + 1 %>
				<% end %>
				<div class="image">
					<img src="" id="thisImageContainer_<%=@i%>" alt="" />
				</div>
				<div>
					<a href="#" id="thisLeftButton_<%=@i%>">&laquo;</a>
					<span id="thisTextContainer_<%=@i%>"></span>
					<a href="#" id="thisRightButton_<%=@i%>">&raquo;</a>
				</div>
				<script type="text/javascript">new ImageFlicker("thisLeftButton_<%=@i%>", "thisRightButton_<%=@i%>", "thisImageContainer_<%=@i%>", "thisTextContainer_<%=@i%>", <%= @images.to_json %> ) </script>
				<% @i += 1 %>
			</div>
			<% else %>
			No Images
			<% end %>
		<% @audios = Audio.find_all_by_artwork_id(@artwork.id)%>
		<% unless @audios.nil? %>
			<% for @audio in @audios%>
				 <%= mp3_player( {:file => "/audio/file/" + @audio.file_relative_path(nil) + ".mp3", :displayheight => 0}, {:height => 40, :id => @audio.id} )%>
			<% end %>
		<% end %>
		<% @videos = Video.find_all_by_artwork_id(@artwork.id)%>
		<% if !(@videos.nil?)%>
			<% for @video in @videos%>
				<%= media_player( 
					{:file => "/video/file/" + video.file_relative_path(subdir = nil)+".flv"},
					{:id => @video.id} )%>
			<% end %>
		<%end%>	
		</div>
		<div class="right">
		  	<script type="text/javascript">
                var languages = [];                
                <% for lang in @desc_languages %>
                languages[<%= lang.id%>] = "<%= lang.description %>"
                <% end %>
			</script>
						  
             <div class="about_art">          
				    <% if @desc_languages.length > 1 %>
                <div style="float:right">
                  Language: <%= render :partial => 'shared/description_select', :object => @desc_languages, :locals => {:value_method => :id, :text_method => :language, :selected => @desc_languages.first.id, :update => 'localized_description'} %>
                </div>
                <% end %>
                <p class="title">About this artwork</p>
              </div>
              
              <div id="localized_description">
                <%= @desc_languages.first.description %>
              </div>              
						</div>
					</div>
</div>

<div class="col2 action">
	<div class="price_container">
		<div>
			<strong><%= Artwork.l_attr('listed for') %> $<%= @artwork.dollar_amount %></strong><br />
			<p><%= Artwork.l_attr('what happens') %> <%= link_to 'Learn More &raquo;', url_for(:controller => 'home', :action => 'learn_more')%></p>
		</div>
		<% if @artwork.quantity > 0 %>
             <button type="button" id="add_to_cart_button">Add to Cart</button>
		<% else %>
			 Sorry, this item is sold out!
		<% end %>
	</div>
</div>
				
<div id="lists">
	<div class="col2">	
		<div id="other_items" class="left">
			<% if @otherByArtist.size != 0 %>
				<%= render :partial => '/artworks/show_summaries', :locals => {:name => Artist.l_attr("other art"), :artworks => @otherByArtist} %>								
			<%end%>

			<% if @otherByArtist.size == 0 and @similarArt.size != 0 %>
				<%= render :partial => '/artworks/show_summaries', :locals => {:name => Artwork.l_attr("similar"), :artworks => @similarArt} %>									
			<%end%>
		</div>
						
		<div id="similiar_items" class="right">
			<% if @similarArt.size != 0 and @otherByArtist.size != 0%>
				<%= render :partial => '/artworks/show_summaries', :locals => {:name => Artwork.l_attr("similar"), :artworks => @similarArt} %>	
			<%end%>
		</div>
	</div>
</div>